<template>
  <div class="basicTable">
    <!--引用表格-->
    <BasicTable @register="registerTable" :rowSelection="rowSelection">
      <!--插槽:table标题-->
      <template #tableTitle>
        <a-button type="primary" @click="handleAdd" preIcon="ant-design:plus-outlined">{{ t('addText') }}</a-button>
      </template>
      <!-- 插槽表格顶部右上 -->
      <template #toolbar>
        <div class="print">{{ t('print') }}</div>
      </template>
    </BasicTable>
    <!-- 表单区域 -->
    <AssetCodeManageModal @register="registerModal" @success="handleSuccess"></AssetCodeManageModal>
  </div>
</template>

<script lang="ts" name="assetcodemanage-assetCodeManage" setup>
  import { BasicTable } from '/@/components/Table';
  import { useModal } from '/@/components/Modal';
  import { useListPage } from '/@/hooks/system/useListPage';
  import AssetCodeManageModal from './components/AssetCodeManageModal.vue';
  import { columns, searchFormSchema } from './AssetCodeManage.data';
  import { list, getImportUrl, getExportUrl } from './AssetCodeManage.api';
  import { useI18n } from '/@/hooks/web/useI18n';
  const { t } = useI18n('common');
  //注册model
  const [registerModal, { openModal }] = useModal();
  //注册table数据
  const { tableContext } = useListPage({
    tableProps: {
      title: t('asset.assetCodeManage.title'),
      api: list,
      columns,
      canResize: false,
      formConfig: {
        //labelWidth: 120,
        schemas: searchFormSchema,
        autoSubmitOnEnter: true,
        showAdvancedButton: true,
        fieldMapToNumber: [],
        fieldMapToTime: [],
      },
      showActionColumn: false,
      // actionColumn: {
      //   width: 120,
      //   fixed: 'right',
      // },
    },
    exportConfig: {
      name: t('asset.assetCodeManage.title'),
      url: getExportUrl,
    },
    importConfig: {
      url: getImportUrl,
      success: handleSuccess,
    },
  });

  const [registerTable, { reload }, { rowSelection, selectedRowKeys }] = tableContext;

  /**
   * 新增事件
   */
  function handleAdd() {
    openModal(true, {
      isUpdate: false,
      showFooter: true,
    });
  }
  /**
  /**
   * 成功回调
   */
  function handleSuccess() {
    (selectedRowKeys.value = []) && reload();
  }
</script>

<style scoped>
  .all {
    display: flex;
    flex-direction: row;
    .basicTable {
      flex: 1;
    }
    .assetList {
      flex: 2;
    }
    .print {
      writing-mode: horizontal-tb;
    }
  }
</style>
